package android.coocoo.common;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.coocoo.models.TaskInfo;
import android.coocoo.views.R;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

@SuppressWarnings("unchecked")
public class TasksListAdapter extends ArrayAdapter {
		
	Activity context;
	private ArrayList<TaskInfo> tasksList;
	private boolean byDate;
		
	public TasksListAdapter(Activity context, int numberOfTasks) {
		super(context, R.layout.task_info_summary, new String[numberOfTasks]);
		this.context=context;
	}
	
	public TasksListAdapter(Activity context, ArrayList<TaskInfo> tasksList) {
		super(context, R.layout.task_info_summary, tasksList);
		Log.e("pass_flag", "ArrayAdapter created");
		this.context=context;
		this.tasksList = tasksList;
	}
	
	public void setTasksList(ArrayList<TaskInfo> tasksList) {
		this.tasksList = tasksList;
	}

	public ArrayList<TaskInfo> getTasksList() {
		return tasksList;
	}

	public void setByDate(boolean byDate) {
		this.byDate = byDate;
	}

	public boolean isByDate() {
		return byDate;
	}
	
	public View getView(final int position, View convertView, ViewGroup parent) {
		LayoutInflater inflater=context.getLayoutInflater();
		View row = convertView;
		if (tasksList != null)
			if (tasksList.size() != 0){
				
				row=inflater.inflate(R.layout.task_info_summary, parent, false);
				
				TextView tvTitle = (TextView)row.findViewById(R.id.tvTitle);
				tvTitle.setText(tasksList.get(position).getTitle());
				
				TextView tvContent = (TextView)row.findViewById(R.id.tvContent);
				if (byDate){
					tvContent.setText(tasksList.get(position).getStartTime().getHours()
										+ ":"
										+ tasksList.get(position).getStartTime().getMinutes());
				}else{
					tvContent.setText(tasksList.get(position).getStartTime().getDate()
							+ "/"
							+ (tasksList.get(position).getStartTime().getMonth()+1)
							+ "/"
							+ tasksList.get(position).getStartTime().getYear()
							+ "\n"
							+ tasksList.get(position).getStartTime().getHours()
							+ ":"
							+ tasksList.get(position).getStartTime().getMinutes());
				}
				
				return(row);
			}else
				return null;
		else
			return null;
	}
}